package com.kayang.webapi.event;


import com.kayang.common.core.UserContext;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.util.Map;

public class Event {

    public static void main(String[] args) {
        String path = "file:\\F:\\Test";
        if(path.startsWith("file:")){
            path = path.substring(5);
        }
        System.out.println(path);
        File dir = new File(path);
        if (dir.isDirectory() && dir.exists()) {
            File[] files = dir.listFiles((dir1, name) -> name.endsWith(".jar") && name.contains("plugin"));

            System.out.println(files.length);
        }
    }
    private static Event event = null;

    public static synchronized Event getUnique(){
        if(event == null){
            event = new Event();
        }
        return  event;
    }

    private Event(){

    }

    private DataEvent<HttpServletRequest , Map, UserContext, Object>  afterStartSession = null;
    private DataEvent<HttpServletRequest ,Map,UserContext, Object>  afterGetData = null;

    private DataEvent<HttpServletRequest , Map,UserContext,Object>  afterPutStart = null;

    private DataEvent<HttpServletRequest ,Map, UserContext,Object>  afterPutData = null;

    private DataEvent<HttpServletRequest ,Map, UserContext,Object>  afterPutClose = null;

    private DataEvent<HttpServletRequest ,Map,UserContext, Object>  afterPutDataBySP = null;


    public DataEvent<HttpServletRequest, Map, UserContext, Object> getAfterStartSession() {
        return afterStartSession;
    }

    public void setAfterStartSession(DataEvent<HttpServletRequest, Map, UserContext, Object> afterStartSession) {
        this.afterStartSession = afterStartSession;
    }

    public DataEvent<HttpServletRequest, Map, UserContext, Object> getAfterGetData() {
        return afterGetData;
    }

    public void setAfterGetData(DataEvent<HttpServletRequest, Map, UserContext, Object> afterGetData) {
        this.afterGetData = afterGetData;
    }

    public DataEvent<HttpServletRequest, Map, UserContext, Object> getAfterPutStart() {
        return afterPutStart;
    }

    public void setAfterPutStart(DataEvent<HttpServletRequest, Map, UserContext, Object> afterPutStart) {
        this.afterPutStart = afterPutStart;
    }

    public DataEvent<HttpServletRequest, Map, UserContext, Object> getAfterPutData() {
        return afterPutData;
    }

    public void setAfterPutData(DataEvent<HttpServletRequest, Map, UserContext, Object> afterPutData) {
        this.afterPutData = afterPutData;
    }

    public DataEvent<HttpServletRequest, Map, UserContext, Object> getAfterPutClose() {
        return afterPutClose;
    }

    public void setAfterPutClose(DataEvent<HttpServletRequest, Map, UserContext, Object> afterPutClose) {
        this.afterPutClose = afterPutClose;
    }

    public DataEvent<HttpServletRequest, Map, UserContext, Object> getAfterPutDataBySP() {
        return afterPutDataBySP;
    }

    public void setAfterPutDataBySP(DataEvent<HttpServletRequest, Map, UserContext, Object> afterPutDataBySP) {
        this.afterPutDataBySP = afterPutDataBySP;
    }

    public void exec(DataEvent dataEvent, HttpServletRequest request, Map<String, Object> par, UserContext uc){
        if(dataEvent != null){
            dataEvent.call(request, par, uc);
        }
    }

    @Override
    public String toString() {
        return "Event{" +
                "afterPutData=" + afterPutData +
                '}';
    }
}
